package com.uls.web.controller.zsw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.zsw.domain.ElectricityBilling;
import com.uls.zsw.service.IElectricityBillingService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 电费结算Controller
 * 
 * @author zsw
 * @date 2024-12-28
 */
@RestController
@RequestMapping("/zsw/electricitybilling")
public class ElectricityBillingController extends BaseController
{
    @Autowired
    private IElectricityBillingService electricityBillingService;

    /**
     * 查询电费结算列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElectricityBilling electricityBilling)
    {
        startPage();
        List<ElectricityBilling> list = electricityBillingService.selectElectricityBillingList(electricityBilling);
        return getDataTable(list);
    }

    /**
     * 导出电费结算列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:export')")
    @Log(title = "电费结算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectricityBilling electricityBilling)
    {
        List<ElectricityBilling> list = electricityBillingService.selectElectricityBillingList(electricityBilling);
        ExcelUtil<ElectricityBilling> util = new ExcelUtil<ElectricityBilling>(ElectricityBilling.class);
        util.exportExcel(response, list, "电费结算数据");
    }

    /**
     * 获取电费结算详细信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:query')")
    @GetMapping(value = "/{billingId}")
    public AjaxResult getInfo(@PathVariable("billingId") Long billingId)
    {
        return success(electricityBillingService.selectElectricityBillingByBillingId(billingId));
    }

    /**
     * 新增电费结算
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:add')")
    @Log(title = "电费结算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElectricityBilling electricityBilling)
    {
        return toAjax(electricityBillingService.insertElectricityBilling(electricityBilling));
    }

    /**
     * 修改电费结算
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:edit')")
    @Log(title = "电费结算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectricityBilling electricityBilling)
    {
        return toAjax(electricityBillingService.updateElectricityBilling(electricityBilling));
    }

    /**
     * 删除电费结算
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:remove')")
    @Log(title = "电费结算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billingIds}")
    public AjaxResult remove(@PathVariable Long[] billingIds)
    {
        return toAjax(electricityBillingService.deleteElectricityBillingByBillingIds(billingIds));
    }

    /**
     * 提交租单审批
     * @param billingId
     * @return
     */

    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:billingsubmit')")
    @Log(title = "电费结算", businessType = BusinessType.EXPORT)
    @GetMapping("/submitBilling/{billingId}")
    public AjaxResult submitBilling(@PathVariable Long billingId){
        return toAjax(electricityBillingService.submit(billingId,getUserId()));
    }

    /**
     * 未审批列表
     * @param electricityBilling
     * @return
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:noconfirm')")
    @GetMapping("/listNo")
    public TableDataInfo listBillingNo(ElectricityBilling electricityBilling){
        startPage();
        List<ElectricityBilling> electricityBillingList=electricityBillingService.noConfirmTask(getUserId(),"electricitybilling");
        return getDataTable(electricityBillingList);
    }

    @GetMapping("/getElectricitybilling/{billingId}")
    public AjaxResult getElectricitybillingInfo(@PathVariable("billingId") Long billingId){
        ElectricityBilling electricityBilling=electricityBillingService.selectElectricityBillingByBillingId(billingId);
        electricityBilling.setTaskCommentVoList(electricityBillingService.getTaskCommentList(electricityBilling.getFlowInstantId()));
        return success(electricityBilling);
    }

    @PreAuthorize("@ss.hasPermi('zsw:electricitybilling:confirmed')")
    @PostMapping("/confirmed")
    public AjaxResult billingConfirmed(@RequestBody ElectricityBilling electricityBilling){
        electricityBillingService.completeTask(electricityBilling,getUserId());
        return toAjax(200);
    }
}
